pic1 = new Image(16, 16); 
pic1.src = "img/loader.gif";

$(document).ready(function(){

	$("#usuario").change(function() { 

		var usr = $("#usuario").val();

		if(usr.length >= 3){
			$("#status").html('<img src="img/loading.gif" align="absmiddle">');

				$.ajax({  
				type: "POST",  
				url: "check.php",  
				data: "usuario="+ usr,  
				success: function(msg){  
			   
			   $("#status").ajaxComplete(function(event, request, settings){ 

				if(msg == 'OK'){ 
					$(this).html('<img src="img/accepted.jpg" align="absmiddle"> <font color="Green"> Nome disponível. </font>  ');
				}  
				else{  
					$(this).html(msg);
				}  
			   
			   });

			 } 
			   
			  }); 

		}
		else{
			$("#status").html('<font color="red">O nome de usuário deve ter no mínimo <strong>3</strong> caractéres.</font>');
		}

	});

	$("#email").change(function() { 

		var mail = $("#email").val();

		if(mail.length > 0){
			$("#status_email").html('<img src="img/loading.gif" align="absmiddle">');

				$.ajax({  
				type: "POST",  
				url: "check.php",  
				data: "email="+ mail,  
				success: function(msg){  
			   
			   $("#status_email").ajaxComplete(function(event, request, settings){ 

				if(msg == 'OK'){ 
					$("#email").removeClass('object_error'); // if necessary
					$("#email").addClass("object_ok");
					$(this).html('<img src="img/accepted.jpg" align="absmiddle"> <font color="Green"> Email disponível. </font>  ');
				}  
				else{  
					$(this).html(msg);
				}  
			   
			   });

			 } 
			   
			  }); 

		}
		else{
			$("#status_email").html('<font color="red">O campo de email deve ser preenchido.</font>');
		}

	});
});